Results 1 to 5 of 5

Thread: Curve could not pass the points

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6

    Default Curve could not pass the points

    Hi all,
    I want to draw a curve in the plot, the value of the first point is relatively small and the value of the last one is relatively large,
    I want to use QwtSplineCurveFitter to make the curve smoother, but the result shows that the curve could not pass the point,
    can you help me to solve this problem?

    this is my code:
    Qt Code:
    1. #include <qapplication.h>
    2. #include <qwt_plot.h>
    3. #include <qwt_plot_curve.h>
    4. #include <qwt_plot_grid.h>
    5. #include <qwt_curve_fitter.h>
    6. #include <qwt_symbol.h>
    7. #include <qwt_legend.h>
    8. #include <qwt_scale_engine.h>
    9.  
    10. int main( int argc, char **argv )
    11. {
    12. QApplication a( argc, argv );
    13.  
    14. QwtPlot plot;
    15. plot.setTitle( "Plot Demo" );
    16. plot.setCanvasBackground( Qt::white );
    17. plot.setAxisScale( QwtPlot::yLeft, 0, 100 );
    18. plot.setAxisScale( QwtPlot::xBottom, 50.0, 0.0 );
    19. plot.insertLegend( new QwtLegend() );
    20. QwtPlotGrid *grid = new QwtPlotGrid();
    21. grid->attach( &plot );
    22.  
    23. QwtPlotCurve *curve = new QwtPlotCurve();
    24. curve->setTitle( "Some Points" );
    25. curve->setPen( QPen( Qt::blue, 1 ) );
    26. curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    27.  
    28. QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
    29. QBrush( Qt::yellow ), QPen( Qt::red, 1 ), QSize( 2, 2 ) );
    30. curve->setSymbol( symbol );
    31.  
    32. curve->setCurveAttribute(QwtPlotCurve::Fitted);
    33. pCurveFitter->setFitMode(QwtSplineCurveFitter::ParametricSpline);
    34. curve->setCurveFitter(pCurveFitter);
    35.  
    36. QPolygonF points;
    37. points << QPointF( 0.0, 2.58258 ) << QPointF( 0.995469, 6.45643 )
    38. << QPointF( 4.11356, 12.9129 ) << QPointF( 12.565, 19.3693 )
    39. << QPointF( 25.1777, 25.8257 ) << QPointF( 45.1747, 51.6515 )
    40. << QPointF( 50.5358, 77.4772) << QPointF( 53.477, 103.303)
    41. <<QPointF( 54.8972, 129.129) << QPointF( 56.9157, 154.954)
    42. << QPointF( 60.1614, 206.606) << QPointF( 63.6644, 284.083)
    43. << QPointF( 66.3, 361.56) << QPointF( 68.3328, 439.038)
    44. << QPointF( 70.5758, 542.341) << QPointF( 74.1964, 800.598)
    45. <<QPointF( 76.675, 1058.86) << QPointF(78.6658, 1317.11)
    46. << QPointF(81.0151, 1833.63) << QPointF(83.0936, 2608.4)
    47. << QPointF(84.9255, 3899.69) << QPointF(86.8342, 6482.26)
    48. << QPointF(87.3439, 8290.06);
    49.  
    50. curve->setSamples( points );
    51.  
    52. curve->attach( &plot );
    53.  
    54. plot.resize( 600, 400 );
    55. plot.show();
    56.  
    57. return a.exec();
    58. }
    To copy to clipboard, switch view to plain text mode 

    and the result picture is here:
    simpleplot.png

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Curve could not pass the points

    Your x values seem to be increasing - so you don't need a ParametricSpline ?

    Uwe

    In SVN trunk you find a first implementation of a fitter using Bezier curves. You can try this one too and if you like it you can copy it to your code as the implementation is compatible with Qwt 6.1.

  3. The following user says thank you to Uwe for this useful post:

    momo (12th February 2014)

  4. #3
    Join Date
    Feb 2014
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6

    Default Re: Curve could not pass the points

    Hi Uwe,
    Thank you for your reply.
    Now I deleted the following code:
    Qt Code:
    1. curve->setCurveAttribute(QwtPlotCurve::Fitted);
    2. // QwtSplineCurveFitter *pCurveFitter = new QwtSplineCurveFitter;
    3. // pCurveFitter->setFitMode(QwtSplineCurveFitter::Auto);
    4. // curve->setCurveFitter(pCurveFitter);
    To copy to clipboard, switch view to plain text mode 
    The curve is still not pass the point.
    Is it Qwt's bug? Or is it my wrong way to use CurveAttribute and CurveFitter?

    Momo

Similar Threads

  1. Replies: 2
    Last Post: 4th September 2011, 22:50
  2. Replies: 3
    Last Post: 23rd February 2011, 08:29
  3. Replies: 4
    Last Post: 6th October 2010, 14:29
  4. Deleting points from a curve dynamically
    By maneesh18187 in forum Qwt
    Replies: 2
    Last Post: 9th February 2010, 19:08
  5. Get the points of a fitted curve
    By giusepped in forum Qwt
    Replies: 4
    Last Post: 25th December 2008, 08:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.